﻿/// <reference path="jquery-1.4.1.js" />
$(document).ready(function () {
    $("#logoPic").hover(function () {
        $("#heimHidden").show();
    }, function () {
        $("#heimHidden").hide();
    });

    $("#titleName").hover(function () {
        $("#heimHidden").show();
    }, function () {
        $("#heimHidden").hide();
    });

    $("#born").click(function () {
        $("#listOfChilds").toggle("slow");
    });

    $("#umsogn").click(function () {
        $("#commentList").toggle("slow");
    });

    $("#synaMinarUpp").click(function () {
        $("#minarUpp").toggle("slow");
    });

    $("#greinar").click(function () {
        $("#minarGreinar").toggle("slow");
    });

    $("#nyttBarn").click(function () {
        $("#formNyttBarn").toggle("slow");
    });

    $("#vinir").click(function () {
        $("#vinaListi").toggle("slow");
    });

    $("#frettirLink").mouseenter(function () {
        $("#frettirDropDown").show().addClass("hovering");
        $("#frettirLink").addClass("hovering");
        $(".hovering").hover(function () {
            $("#frettirDropDown").show();
        }, function () {
            $("#frettirDropDown").hide();
            $(".hovering").removeClass("hovering");
        });
    });

    $("#greinarLink").mouseenter(function () {
        $("#greinarDropDown").show().addClass("hovering");
        $("#greinarLink").addClass("hovering");
        $(".hovering").hover(function () {
            $("#greinarDropDown").show();
        }, function () {
            $("#greinarDropDown").hide();
            $(".hovering").removeClass("hovering");
        });
    });

    $("#spurningarLink").mouseenter(function () {
        $("#spurningarDropDown").show().addClass("hovering");
        $("#spurningarLink").addClass("hovering");
        $(".hovering").hover(function () {
            $("#spurningarDropDown").show();
        }, function () {
            $("#spurningarDropDown").hide();
            $(".hovering").removeClass("hovering");
        });
    });

    $("#fagAdilarLink").mouseenter(function () {
        $("#fagAdilarDropDown").show().addClass("hovering");
        $("#fagAdilarLink").addClass("hovering");
        $(".hovering").hover(function () {
            $("#fagAdilarDropDown").show();
        }, function () {
            $("#fagAdilarDropDown").hide();
            $(".hovering").removeClass("hovering");
        });
    });

    $("#hagnytarLink").mouseenter(function () {
        $("#hagnytarDropDown").show().addClass("hovering");
        $("#hagnytarLink").addClass("hovering");
        $(".hovering").hover(function () {
            $("#hagnytarDropDown").show();
        }, function () {
            $("#hagnytarDropDown").hide();
            $(".hovering").removeClass("hovering");
        });
    });

    $("#kjosaButton").click(function () {
        var choiceID = $("input:radio[name=surveyChoice]:checked").val();
        var ID = { "ID": choiceID, "random": "Just to fill space" };
        $(".surveyRemove").remove();
        $("#kjosaButton").remove();
        $.post("/Home/UpdateSurvey", ID, function (n) { $("#surveyTemplate").tmpl(n).appendTo("#surveyChoices"); });
    });
    var options = 3;
    $("#optionButtonMore").click(function () {
        var item = { "remove": options, "random": "no matter" };
        $("#optionsTemplate").tmpl(item).appendTo("#choiceOptions");
        options = options + 1;
        if (options > 3) {
            $("#optionButtonLess").show();
        }
    });

    $("#optionButtonLess").click(function () {
        options = options - 1;
        $("#remove" + options).remove();
        if (options == 3) {
            $("#optionButtonLess").hide();
        }
    });
});

function saveGrein(id) {
    var ArticleID = { "ID": "", "UserID": "", "informationBaseID": id };
    $.post("/MySite/AddGrein", ArticleID, function (data) {
        if (data == "Þú hefur þegar bætt þessari grein í safnið þitt") {
            $(("#") + id).html("Grein nú þegar í safni").css({ "color": "red", "position": "absolute", "margin-left": "20px", "margin-top": "14px" }).fadeOut(5000);
        }
        $(("#baetaSafn") + id).css("display","none");
    });
    event.preventDefault();
}

function saveContact(id) {
    var ArticleID = { "ID": "", "UserID": "", "informationBaseID": id };
    $("#adeinsNidur").html("");
    $.post("/MySite/AddUserToContacts", ArticleID, function (data) {
        if (data == "You have already added this User") {
            $("#adeinsNidur").html("Þessi notandi er núþegar á vinalista").css("color","red").fadeOut(5000);
        }
        else if(data=="You cannot befriend yourself"){
            $("#adeinsNidur").html("Þú getur ekki bætt sjálfum þér á vinalista").css("color","red").fadeOut(5000);
        }
    });
}

function deleteGrein(id, userID) {
    var ArticleID = { "ID": "", "userID": userID, "informationBaseID": id };
    $(("#") + id).css("display", "none");
    $.post("/MySite/DeleteGrein", ArticleID, function (data) {
    });
}

function DeleteUserContact(ID, userID) {
    var articleID = { "ID": "", "userID1": userID, "userID2": ID };
    $(("#notandi") + userID).remove();
    $.post("/MySite/DeleteUserContact", articleID, function () {
    });
}